"""
@Author  : 康帅
@Time    : 2021/8/7 15:34
@Function: 力扣：7.正数反转(容易)
"""


class Solution(object):

    def reverse(self, x):
        """
        :type x: int
        :rtype: int
        """
        num = 0
        # abs 返回参数的绝对值
        a = abs(x)

        while a != 0:
            temp = a % 10
            num = num * 10 + temp
            a = int(a/10)

        if x > 0 and num < 2147483647:
            return num
        elif x < 0 and num <= 2147483647:
            return -num
        else:
            return 0


if __name__ == '__main__':
    data = Solution()
    print(data.reverse(321))
